<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <!-- 开发环境版本，包含了有帮助的命令行警告 -->
    <script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
    <style>
        * {
            margin: 0;
            padding: 0;
        }
        
        ul li {
            list-style: none;
        }
        
        #app {
            width: 600px;
            margin: 100px auto;
            text-align: center;
            height: 800px;
        }
        
        h1 {
            font-weight: 400;
            color: rgb(235, 128, 57);
            margin-bottom: 40px;
        }
        
        #app input {
            width: 300px;
            height: 30px;
            border: 0;
            /* border: 1px solid rgba(0, 0, 0, .3); */
            box-shadow: 0 0 4px 1px #ccc;
            outline: none;
            margin: auto;
        }
        
        #app input::placeholder {
            font-style: italic;
            color: #ccc;
            padding-left: 6px;
        }
        
        .main {
            width: 300px;
            margin: auto;
        }
        
        .main .todo {
            position: relative;
            height: 35px;
            line-height: 35px;
            box-shadow: 0 0 4px 1px #ccc;
        }
        
        .main .todo .view {
            width: 100%;
            background-color: red;
        }
        
        .view .index {
            position: absolute;
            left: 2px;
            color: gray;
        }
        
        .view label {
            position: absolute;
            left: 34px;
            color: gray;
        }
        
        .destroy {
            position: absolute;
            right: 12px;
            top: 9px;
            border: 0;
            outline: none;
            background-color: #fff;
            display: none;
        }
        
        .todo:hover .destroy {
            display: block;
            cursor: pointer;
        }
        
        .footer {
            position: relative;
            width: 300px;
            margin: auto;
            box-shadow: 0 0 4px 1px #ccc;
            text-align: left;
        }
        
        .clear {
            position: absolute;
            right: 2px;
            top: 2px;
            border: 0;
            background-color: #fff;
            outline: none;
            cursor: pointer;
        }
    </style>
</head>

<body>
    <div id="app">
        <h1>记事本</h1>
        <!-- 输入框 -->
        <input type="text" placeholder="请输入任务" autofocus v-model="inputValue" @keyup.enter="add">
        <!-- 列表区域 -->
        <section class="main">
            <ul class="todo-list">
                <li class="todo" v-for="(items,index) in list">
                    <div class="view">
                        <span class="index">{{index+1}}.</span>
                        <label for="">{{items}}</label>
                        <button class="destroy" @click="remove(index)">x</button>
                    </div>
                </li>
            </ul>
        </section>
        <!-- 统计和清空 -->
        <footer class=" footer "><span v-if="list.length!=0"><strong>{{list.length}}</strong> Note Books</span> <button v-show="list.length!=0" class="clear" @click="clear">clear</button></footer>
    </div>
    <script>
        var app = new Vue({
            el: '#app',
            data: {
                list: ['写代码', '吃饭饭', '睡觉觉'],
                inputValue: '好好学习，天天向上',

            },
            methods: {
                add: function() {
                    this.list.push(this.inputValue)
                },
                remove: function(index) {
                    console.log('删除');
                    console.log(index);
                    this.list.splice(index, 1)
                },
                clear: function() {
                    this.list = [];
                }
            }
        })
    </script>
</body>

</html>